import request from '../../utils/request';

// shopping-cart 管理相关 API

// 更新购物车商品
export const updateCartItem = (data) => {
    return request({
        url: '/order/shopping-cart',
        method: 'put',
        data: data,
    });
};

// 添加商品到购物车
export const addToCart = (data) => {
    return request({
        url: '/order/shopping-cart',
        method: 'post',
        data: data,
    });
};

// 选中/取消选中购物车商品
export const selectCartItem = (id, params) => {
    return request({
        url: `/order/shopping-cart/${id}/select`,
        method: 'put',
        params: params,
    });
};

// 全选/取消全选购物车商品
export const selectAllCartItems = (memberId, params) => {
    return request({
        url: `/order/shopping-cart/select-all/${memberId}`,
        method: 'put',
        params: params,
    });
};

// 批量查询购物车商品
export const getCartItemsByIds = (data) => {
    return request({
        url: '/order/shopping-cart/batch',
        method: 'post',
        data: data,
    });
};

// 批量删除购物车商品
export const batchRemoveFromCart = (data) => {
    return request({
        url: '/order/shopping-cart/batch',
        method: 'delete',
        data: data,
    });
};

// 查询会员购物车列表
export const getMemberCartList = (memberId) => {
    return request({
        url: `/order/shopping-cart/member/${memberId}`,
        method: 'get',
    });
};

// 查询购物车商品数量
export const getCartItemCount = (memberId) => {
    return request({
        url: `/order/shopping-cart/count/${memberId}`,
        method: 'get',
    });
};

// 删除购物车商品
export const removeFromCart = (id) => {
    return request({
        url: `/order/shopping-cart/${id}`,
        method: 'delete',
    });
};

// 清空购物车
export const clearCart = (memberId) => {
    return request({
        url: `/order/shopping-cart/clear/${memberId}`,
        method: 'delete',
    });
};

